import com.itheima.security.PasswordEncoderFactories;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.password.DelegatingPasswordEncoder;
import org.springframework.security.crypto.password.MessageDigestPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

import java.util.HashMap;
import java.util.Map;


public class DomainUserDetailsService {

    public static void main(String[] args) {
        String password = "123";

        PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
        String encode = encoder.encode(password);
        System.out.println(encode);
        System.out.println(encoder.matches(password, encode) == true ? "相等" : "不相等");
        //结果    {bcrypt}$2a$10$7nWPfI/2IrK0L946A0/FzOp28.Go8bQMwi5Vei1c4UQ0rMW26HddG
        //        相等



        Map<String, PasswordEncoder> encoders = new HashMap<>();
        encoders.put("MD5", new MessageDigestPasswordEncoder("MD5"));
        DelegatingPasswordEncoder encoder1 = new DelegatingPasswordEncoder("MD5", encoders);
        String encode1 = encoder1.encode(password);
        System.out.println(encode1);
        System.out.println(encoder1.matches(password, encode1) == true ? "相等" : "不相等");
        //结果  {MD5}{N8BRedNGqPYNJP391yYyEqXJVBLRM7REi9uDiPKBfeo=}75e7979d78143b74fba77d988701e694
        //      相等

    }
}
